package com.example.controller;

import com.example.common.Result;
import com.example.entity.GymInfo;
import com.example.entity.User;
import com.example.service.GymService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/gym")
public class GymController {

    @Autowired
    GymService gymService;

    /**
     * 新增
     */

    @PostMapping("/add")
    public Result add (@RequestBody GymInfo gymInfo){
        gymService.add(gymInfo);
        return Result.success();
    }

    /**
     * 删除
     */

    @DeleteMapping("/delete/{id}")
    public Result delete (@PathVariable Integer id){
        gymService.deleteById(id);
        return Result.success();
    }
    /**
     * 更新
     */

    @PutMapping("/update")
    public  Result update (@RequestBody GymInfo gymInfo)
    {
        gymService.updateById(gymInfo);
        return Result.success();
    }
    /**
     * 列表
     */

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                             String gymName, String gymLocation){
        PageInfo<GymInfo> PageInfo = gymService.selectPage(pageNum,pageSize, gymName,gymLocation);
        return Result.success(PageInfo);
    }


}
